package com.next.muscu.data;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "users", catalog = "jaydb", schema = "")
public class User implements Comparable<User> ,MyDataObject, java.io.Serializable {

	PropertyChangeSupport ppChangeSupport = new PropertyChangeSupport(this);
	
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        @Basic(optional = false)
	@Column(name = "ID")
	Integer id;
        @Column(name = "LASTNAME" , length=50 )
	String lastName ;
	@Column(name = "FIRSTNAME" , length=50)
        String firstName;
	
	public User()
	{
		super();
		this.id = new Integer(0);
		this.lastName = new String();
		this.firstName = new String();
		
	}
	
	public User(Integer id,String lastName, String firstName) {
		super();
		this.id = id;
		this.lastName = lastName;
		this.firstName = firstName;
	}

	@Override
	public boolean copy(MyDataObject o) {
		if(o instanceof User)
		{
		setId(o.getId());
		setLastName(((User) o).getLastName());
		setFirstName(((User) o).getFirstName());
		return true;
		}
		return false;
	}

	@Override
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		Integer old = this.id;
		this.id = id;
		ppChangeSupport.firePropertyChange("firstName", old , this.id);
	}
	
	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		String old = this.lastName;
		this.lastName = lastName;
		ppChangeSupport.firePropertyChange("lastName", old , this.lastName);
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		String old = this.firstName;
		this.firstName = firstName;
		ppChangeSupport.firePropertyChange("firstName", old , this.firstName);
	}

	@Override
	public void Create() {
		 id = new Integer(0);
		 lastName = new String();
		 firstName = new String();

	}

	public void addPropertyChangeListener(PropertyChangeListener listener) {
		ppChangeSupport.addPropertyChangeListener(listener);
	}
	public void addPropertyChangeListener(String propertyName,
			PropertyChangeListener listener) {
		ppChangeSupport.addPropertyChangeListener(propertyName, listener);
	}
	public PropertyChangeListener[] getPropertyChangeListeners() {
		return ppChangeSupport.getPropertyChangeListeners();
	}
	public PropertyChangeListener[] getPropertyChangeListeners(
			String propertyName) {
		return ppChangeSupport.getPropertyChangeListeners(propertyName);
	}
	public void removePropertyChangeListener(PropertyChangeListener listener) {
		ppChangeSupport.removePropertyChangeListener(listener);
	}
	public void removePropertyChangeListener(String propertyName,
			PropertyChangeListener listener) {
		ppChangeSupport
				.removePropertyChangeListener(propertyName, listener);
	}

	@Override
	public int compareTo(User o) {
		return this.getId().compareTo(o.getId());
	}
	
	@Override
	 public boolean equals(Object o) {
	        if (!(o instanceof User))
	            return false;
	        User e = (User)o;
	        return e.getId().equals(id);
	    }
	@Override
	public String toString() {
		return "User [ id=" + id
				+ ", lastName=" + lastName + ", firstName=" + firstName + "]";
	}

	@Override
	    public int hashCode() {
	        return id.hashCode();
	    }

}
